<template>
  <div class="home">
    <h3>数据展示</h3>
    <el-table :data="tableData" style="width: 100%" :row-class-name="tableRowClassName">
      <el-table-column prop="date" label="日期" width="180"></el-table-column>
      <el-table-column prop="name" label="姓名" width="180"></el-table-column>
      <el-table-column prop="address" label="地址"></el-table-column>
    </el-table>
    <!-- <button @click="btn">获取数据</button> -->
  </div>
</template>

<style>
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>

<script>
import { mapState } from "vuex";
export default {
  methods: {
    tableRowClassName({ rowIndex }) {
      if (rowIndex === 1) {
        return "warning-row";
      } else if (rowIndex === 3) {
        return "success-row";
      }
      return "";
    },
    // ...mapActions({
    //   btn: "change_table_data"
    // })
  },
  computed:{
      ...mapState(['tableData'])
  },
  created() {
      //获取数据
      this.$store.dispatch('change_table_data')
  },
  
};
</script>
<style scoped>
.home {
  padding-top: 20px;
  text-align: center;
  width: 80%;
  margin: 0 auto;
}
</style>